home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / BBEdit / MacBob 1.0ß2 / Examples / HexDump1.bob < prev    next >
Encoding:
Text File  |  1995-12-07  |  718 b   |  46 lines  |  [TEXT/R*ch]

  1. /***
  2.  *
  3.  *    HexDump1.bob - Example program to dump any file in hexidecimal.
  4.  *
  5.  ***/
  6.  
  7. main ()
  8. {
  9. //    if (getfile("TEXT"))
  10.     if (getfile())
  11.         ProcessFile();
  12.     else
  13.         print("*** ERROR: Couldn't get file ***\n");
  14. }
  15.  
  16.  
  17. HexByte (byte ; str, n)
  18. {
  19.     str = newstring(2);
  20.     n = (byte >> 4) & 15;
  21.     str[0] = (n <= 9 ? '0' : 'A' - 10) + n;
  22.     n = byte & 15;
  23.     str[1] = (n <= 9 ? '0' : 'A' - 10) + n;
  24.     return str;
  25. }
  26.  
  27.  
  28. ProcessFile ( ; c, i, line)
  29. {
  30.     line = "000000: ";
  31.     i = 0;
  32.  
  33.     while ((c = getc(stdin)) != -1) {
  34.         line += " " + HexByte(c);
  35.         ++i;
  36.         if ((i & 15) == 0) {
  37.             print(line, "\n");
  38.             line = HexByte(i >> 16) + HexByte(i >> 8) +
  39.                                       HexByte(i) + ": ";
  40.         }
  41.     }
  42.     if (sizeof(line) != 0)
  43.         print(line, "\n");
  44.     print("<END>\n");
  45. }
  46.